<?php namespace app\admin\controller;

use houdunwang\view\View;

class Link extends Common {
    protected $db;
    public function __init(){
        $this->db = new \system\model\Link();
    }

    public function index(){
        //获取数据库link内容
        $data = $this->db->getAllLink(3);
        //p($data);
        //分配变量
        View::with('data',$data);
        return view();
    }
    //添加友链
    public function store(){
        if(IS_POST){
            //p($_POST);
            if($this->db->store()){
                message('添加有链成功',u('index'),'success',0.5);
            };
            message('添加友链失败','back','error',0.5);
        }
        return view();
    }
    //编辑有链
    public function edit(){
        if(IS_POST){
            //p($_POST);
            if($this->db->edit()){
                message('编辑友链成功',u('index'),'success',0.5);
            }
            message('编辑友链失败','back','error',0.5);
        }
        //获取旧数据
        $lid = q('get.lid');
        $oldLink = $this->db->getOldLink($lid);
        View::with('oldLink',$oldLink);
        return view();
    }
    //删除友链
    public function del(){
        //获取旧数据
        $lid = q('get.lid');
        $res = $this->db->delLink($lid);
        if($res){
            message('删除友链成功',u('index'),'success',0.5);
        }
        message('删除友链失败','back','error',0.5);
        return view();
    }
}
